import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class TestSharedPrefs extends StatefulWidget {
  @override
  _TestSharedPrefsState createState() => _TestSharedPrefsState();
}

class _TestSharedPrefsState extends State<TestSharedPrefs> {
  String _status = 'Testing SharedPreferences...';

  @override
  void initState() {
    super.initState();
    _testSharedPrefs();
  }

  Future<void> _testSharedPrefs() async {
    try {
      final prefs = await SharedPreferences.getInstance();
      await prefs.setString('test_key', 'test_value');
      final value = prefs.getString('test_key');
      
      setState(() {
        _status = 'Success! Value: $value';
      });
    } catch (e) {
      setState(() {
        _status = 'Error: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('SharedPreferences Test')),
      body: Center(
        child: Text(_status),
      ),
    );
  }
}